#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<queue>
#define x first
#define y second
using namespace std;
using pii = pair<int, int>;
using piii = pair<int, pii>;
const int N = 310;
priority_queue<piii, vector<piii>, greater<piii> > q;
char g[N][N];
int cnt[N][N];
int n, T, ans;
int dx[] = { -1,-1,-1,0,1,1,1,0 }, dy[] = { -1,0,1,1,1,0,-1,-1 };
int cal(int x, int y)
{
    int c = 0;
    for (int i = 0; i < 8; i++)
    {
        int a = x + dx[i], b = y + dy[i];
        if (a<0 || b<0 || a>n || b>n) continue;
        if (g[a][b] == '*') c++;
    }
    return c;
}
void dfs(int x, int y)
{
    g[x][y] = cnt[x][y] + '0';
    if (cnt[x][y] != 0) return;
    for (int i = 0; i < 8; i++)
    {
        int a = x + dx[i], b = y + dy[i];
        if (a<0 || b<0 || a>n || b>n) continue;
        if (g[a][b] != '.') continue;
        dfs(a, b);
    }
}
int main()
{
    cin >> T;
    for (int k = 1; k <= T; k++)
    {
        cin >> n;
        ans = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                cin >> g[i][j];
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (g[i][j] != '*')
                {
                    cnt[i][j] = cal(i, j);
                    q.push({ cnt[i][j],{i,j} });
                }
            }
        }
        while (q.size())
        {
            auto t = q.top();
            q.pop();
            int x = t.y.x, y = t.y.y;
            if (g[x][y] == '.')
            {
                //cout<<x<<" "<<y<<endl;
                dfs(x, y);
                ans++;
            }
        }
        printf("Case #%d: %d\n", k, ans);
    }
    return 0;
}